package net.i_tatami.slab.mazesearch.agent;

import net.i_tatami.slab.mazesearch.maze.Maze;


public class LHMario extends Mario{

	public LHMario(Maze maze){
		super(maze);
		this.direction = Maze.SOUTH; 
		this.location = maze.getStart();
		sense();
	}
	
	public void step(){
		sense();
		decideAction();
		takeAction();
	}

	public void decideAction(){
		if((leftSensorInfo == Maze.ROAD)){
			this.action = Action.TURNLEFT;
		}
		else if((leftSensorInfo == Maze.WALL) && (frontSensorInfo == Maze.ROAD)){
			this.action = Action.KEEP;
		}
		else if((leftSensorInfo == Maze.WALL) && (frontSensorInfo == Maze.WALL) && (rightSensorInfo == Maze.ROAD)){
			this.action = Action.TURNRIGHT;
		}
		else{
			this.action = Action.UTURN;
		}
	}

	public void takeAction(){
		switch(action){
		case TURNLEFT:
			switch(direction){
			case Maze.NORTH:
				this.direction = Maze.WEST;
				break;
			case Maze.SOUTH:
				this.direction = Maze.EAST;
				break;
			case Maze.WEST:
				this.direction = Maze.SOUTH;
				break;
			case Maze.EAST:
				this.direction = Maze.NORTH;
				break;
			}
			break;
		case TURNRIGHT:
			switch(direction){
			case Maze.NORTH:
				this.direction = Maze.EAST;
				break;
			case Maze.SOUTH:
				this.direction = Maze.WEST;
				break;
			case Maze.WEST:
				this.direction = Maze.NORTH;
				break;
			case Maze.EAST:
				this.direction = Maze.SOUTH;
				break;
			}
			break;
		case UTURN:
			switch(direction){
			case Maze.NORTH:
				this.direction = Maze.SOUTH;
				break;
			case Maze.SOUTH:
				this.direction = Maze.NORTH;
				break;
			case Maze.WEST:
				this.direction = Maze.EAST;
				break;
			case Maze.EAST:
				this.direction = Maze.WEST;
				break;
			}
			break;
		}
		switch(direction){
		case Maze.NORTH:
			this.location.y--;
			break;
		case Maze.SOUTH:
			this.location.y++;
			break;
		case Maze.WEST:
			this.location.x--;
			break;
		case Maze.EAST:
			this.location.x++;
			break;
		}
	}
}
